//
//  TaskManagerDetailHeadView.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2021/3/22.
//  Copyright © 2021 吕晶. All rights reserved.
//

#import "TaskManagerDetailHeadView.h"

@interface TaskManagerDetailHeadView ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *taskTitleLab;
@property (nonatomic, strong) UILabel *taskLab;
@property (nonatomic, strong) UILabel *price1TitleLab;
@property (nonatomic, strong) UILabel *price1Lab;
@property (nonatomic, strong) UILabel *price1UnitLab;

@end

@implementation TaskManagerDetailHeadView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = Color_backgroundColor;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self addSubview:self.bgView];
        
        self.titleLab = [UILabel new];
        self.titleLab.textColor = HexColor(0x2B2C44);
        self.titleLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.titleLab];
        
        self.taskTitleLab = [UILabel new];
        self.taskTitleLab.textColor = HexColor(0x9C9DB3);
        self.taskTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.taskTitleLab];
        
        self.taskLab = [UILabel new];
        self.taskLab.textColor = HexColor(0x2B2C44);
        self.taskLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.taskLab];
        
        self.price1TitleLab = [UILabel new];
        self.price1TitleLab.textColor = HexColor(0x9C9DB3);
        self.price1TitleLab.font = BoldFontOfSize(14);
        [self.bgView addSubview:self.price1TitleLab];
        
        self.price1Lab = [UILabel new];
        self.price1Lab.textColor = HexColor(0xF35959);
        self.price1Lab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.price1Lab];
        
        self.price1UnitLab = [UILabel new];
        self.price1UnitLab.textColor = HexColor(0x585974);
        self.price1UnitLab.font = [UIFont systemFontOfSize:16];
        [self.bgView addSubview:self.price1UnitLab];
    }
    return self;
}

-(void)setModel:(TaskManagerDetailModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.frame = CGRectMake(15, 10, ScreenW - 30, self.model.is_sta_type == 1 ? 115 : 87);
    
    self.titleLab.text = [NSString stringWithFormat:@"任务单号：%@",self.model.sta_num];
    self.titleLab.frame = CGRectMake(15, 20, self.bgView.nim_width - 30, 19);
    
    self.taskTitleLab.text = @"任务来源：";
    [self.taskTitleLab sizeToFit];
    self.taskTitleLab.nim_left = 15;
    self.taskTitleLab.nim_top = self.titleLab.nim_bottom + 5;
    
    self.taskLab.text = self.model.t_name;
    self.taskLab.frame = CGRectMake(self.taskTitleLab.nim_right, self.taskTitleLab.nim_top, self.bgView.nim_width - 15 - self.taskTitleLab.nim_left, self.taskTitleLab.nim_height);
    
    
    if (self.model.is_fa == 1) {
        self.price1UnitLab.text = @"元";
        [self.price1UnitLab sizeToFit];
        self.price1UnitLab.nim_left = self.bgView.nim_width - 15 - self.price1UnitLab.nim_width;
        self.price1UnitLab.nim_top = self.taskTitleLab.nim_bottom + (self.bgView.nim_height - self.taskTitleLab.nim_bottom - self.price1UnitLab.nim_height) * 0.5;
        
        self.price1Lab.text = self.model.price;
        [self.price1Lab sizeToFit];
        self.price1Lab.nim_left = self.price1UnitLab.nim_left - 3 - self.price1Lab.nim_width;
        self.price1Lab.nim_centerY = self.price1UnitLab.nim_centerY;
        
        self.price1TitleLab.text = @"报价";
        [self.price1TitleLab sizeToFit];
        self.price1TitleLab.nim_left = self.price1Lab.nim_left - 20 - self.price1TitleLab.nim_width;
        self.price1TitleLab.nim_centerY = self.price1Lab.nim_centerY;
    }else {
        self.price1UnitLab.frame = CGRectZero;
        self.price1Lab.frame = CGRectZero;
        self.price1TitleLab.frame = CGRectZero;
    }
}

@end
